Match = cc.Node.extend({
	ctor:function(p){
		this._super();
		p.addChild(this, 7, TAG_MATCH_NODE);
		this.loadMatchBox();
	},
	loadMatchBox : function(){
		this.setCascadeOpacityEnabled(true);
		var box = new Button(this, 10, TAG_MATCH_BOX, "#lamp/match_box.png",this.callback);
	},
	loadMatch : function(){
		var match = new Button(this, 10, TAG_MATCH, "#lamp/match.png",this.callback);
		match.setOpacity(0);
		var spawn = cc.spawn(cc.fadeIn(0.5),cc.moveTo(0.5, cc.p(100,0))); 
		var seq = cc.sequence(spawn, this.getParent().callNext);
		match.runAction(seq);
	},
	lightMatch : function(p){
		var move = cc.moveTo(0.5,cc.p(0,0));
		var move2 = cc.moveTo(0.3, cc.p(60,-30));
		var func = cc.callFunc(function(){
			var fire = new cc.Sprite("#lamp/fire.png");
			fire.setAnchorPoint(cc.p(0, 0.5));
			fire.setPosition(-10,18);
			fire.setScale(0);
			p.addChild(fire);
			var seq = cc.sequence(cc.scaleTo(0.3,1),this.getParent().callNext);
			fire.runAction(seq)
		}, this);
		var seq = cc.sequence(move, move2, func);
		p.runAction(seq);
	},
	lightLamp : function(p){
		var ber = cc.bezierTo(1, [cc.p(20, 0),cc.p(20, -160),cc.p(-60, -160)]);
		var delay = cc.delayTime(0.5);
		var func1 = cc.callFunc(function(){
			var lamp = this.getParent().getChildByTag(TAG_LAMP);
			lamp.loadFire();
		}, this);
		var func2 = cc.callFunc(function(){
			this.kill();
		}, this); 
		var seq = cc.sequence(ber, delay, func1, delay, this.getParent().callNext,func2);
		p.runAction(seq);
	},
	kill:function(){
		var seq = cc.sequence(cc.fadeOut(0.5),cc.callFunc(function(){
			this.removeFromParent(true);	
		}, this))
		this.runAction(seq);
		// 等待2-3min，
		this.getParent().clock.loadTip("#tool/tip1.png");
		this.getParent().clock.doTime(3, 0.5);
	},
	callback:function(p){
		switch(p.getTag()){
		case TAG_MATCH_BOX:
			// 取出一根火柴
			this.loadMatch();
			break;
		case TAG_MATCH:
			if(gg.flow.flow.action == ACTION_DO1){
				// 点燃火柴
				this.lightMatch(p);
			} else if(gg.flow.flow.action == ACTION_DO2){
				// 点燃酒精灯
				this.lightLamp(p);
			}
			break;
		}
	}
});
